// main.ts`
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
import { library } from '@fortawesome/fontawesome-svg-core'
import { 
  faMountain, 
  faRoute,
  faStar,
  faUser,
  faBars,
  faPlus,
  faSun,
  faCloudSun,
  faCloudShowersHeavy,
  faCloud,
  faChevronDown,
  faTimes,
  faCamera
} from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import { useUserStore } from '@/stores/user'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'

// 导入全局样式
import './assets/main.css'

// 配置FontAwesome
library.add(
  faMountain,
  faRoute,
  faStar,
  faUser,
  faBars,
  faPlus,
  faSun,
  faCloudSun,
  faCloudShowersHeavy,
  faCloud,
  faChevronDown,
  faTimes,
  faCamera
)

// 配置Cesium静态资源路径
window.CESIUM_BASE_URL = '/node_modules/cesium/Build/Cesium/'

const app = createApp(App)
const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)
app.use(pinia)
// 恢复登录状态（必须在 app.use(pinia) 之后，app.use(router) 之前）
useUserStore().initUserState()
app.use(router)
app.component('font-awesome-icon', FontAwesomeIcon)

// 全局错误捕获
app.config.errorHandler = (err, instance, info) => {
  // 输出到控制台
  console.error('全局错误:', err, info)
}

app.mount('#app')